<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\logic\skits;


use app\common\model\app\App;
use app\common\model\skits\Skits;
use app\common\logic\BaseLogic;
use app\common\model\skits\SkitsActor;
use app\common\model\skits\SkitsCategory;
use app\common\model\skits\SkitsEpisodes;
use app\common\model\skits\SkitsWechatAudit;
use app\common\service\douyin\DouyinService;
use app\common\service\wechat\WechatService;
use think\facade\Db;


/**
 * Skits逻辑
 * Class SkitsLogic
 * @package app\adminapi\logic
 */
class SkitsLogic extends BaseLogic
{

    /**
     * 获取所有短剧
     *
     * @param $appId
     * @return Skits[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getAll($appId)
    {
        $app = App::find($appId);
        if ($app->channel == 1) {
            $query = Skits::where('douyin_status', 3);
        } else {
            $query = Skits::where('wechat_status', 0);
        }

        return $query->field('id, skits_name,thumb,episodes_count')->select()->toArray();
    }


    /**
     * @notes 添加
     * @param array $params
     * @return bool
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public static function add(array $params): bool
    {
        Db::startTrans();
        try {
            $skits = Skits::create([
                'skits_name'              => $params['skits_name'] ?? '',
                'category_id'             => implode(',', $params['category_id'] ?? []),
                'producer_name'           => $params['producer_name'] ?? '',
                'production_organisation' => $params['production_organisation'] ?? '',
                'director'                => $params['director'] ?? '',
                'recommendation'          => $params['recommendation'] ?? '',
                'intro'                   => $params['intro'] ?? '',
                'thumb'                   => $params['thumb'] ?? '',
                'episodes_count'          => $params['episodes_count'] ?? 0,
                'duration'                => $params['duration'] ?? 0,
                'year'                    => $params['year'] ?? 0,
                'is_finish'               => $params['is_finish'],
                'is_hot'                  => $params['is_hot'],
                'is_rank'                 => $params['is_rank'],
                'rank_sort'               => $params['rank_sort'],
                'is_free'                 => $params['is_free'],
                'pay_episodes'            => $params['pay_episodes'],
                'price_type'              => $params['price_type'],
                'episodes_k_coin'         => $params['episodes_k_coin'],
                'cost_of_production'      => $params['cost_of_production'] ?? 0
            ]);

            $actors = $params['actors'] ?? [];

            $insertData = [];
            $time       = time();
            foreach ($actors as $actor) {
                $insertData[] = [
                    'skits_id'    => $skits->id,
                    'name'        => $actor['name'] ?? '',
                    'photo'       => $actor['photo'] ?? '',
                    'role'        => $actor['role'] ?? '',
                    'profile'     => $actor['profile'] ?? '',
                    'create_time' => $time,
                    'update_time' => $time
                ];
            }
            SkitsActor::insertAll($insertData);

            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            self::setError($e->getMessage());
            return false;
        }
    }


    /**
     * @notes 编辑
     * @param array $params
     * @return bool
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public static function edit(array $params): bool
    {
        Db::startTrans();
        try {
            Skits::where('id', $params['id'])->update([
                'skits_name'              => $params['skits_name'] ?? '',
                'category_id'             => implode(',', $params['category_id'] ?? []),
                'producer_name'           => $params['producer_name'] ?? '',
                'production_organisation' => $params['production_organisation'] ?? '',
                'director'                => $params['director'] ?? '',
                'recommendation'          => $params['recommendation'] ?? '',
                'intro'                   => $params['intro'] ?? '',
                'thumb'                   => $params['thumb'] ?? '',
                'episodes_count'          => $params['episodes_count'] ?? 0,
                'duration'                => $params['duration'] ?? 0,
                'year'                    => $params['year'] ?? 0,
                'is_finish'               => $params['is_finish'],
                'is_hot'                  => $params['is_hot'],
                'is_rank'                 => $params['is_rank'],
                'rank_sort'               => $params['rank_sort'],
                'is_free'                 => $params['is_free'],
                'pay_episodes'            => $params['pay_episodes'],
                'price_type'              => $params['price_type'],
                'episodes_k_coin'         => $params['episodes_k_coin'],
                'cost_of_production'      => $params['cost_of_production'] ?? 0
            ]);

            // 删除原有演员信息
            SkitsActor::where('skits_id', $params['id'])->delete();

            $actors     = $params['actors'] ?? [];
            $insertData = [];
            $time       = time();
            foreach ($actors as $actor) {
                $insertData[] = [
                    'skits_id'    => $params['id'],
                    'name'        => $actor['name'] ?? '',
                    'photo'       => $actor['photo'] ?? '',
                    'role'        => $actor['role'] ?? '',
                    'profile'     => $actor['profile'] ?? '',
                    'create_time' => $time,
                    'update_time' => $time
                ];
            }
            SkitsActor::insertAll($insertData);

            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            self::setError($e->getMessage());
            return false;
        }
    }

    /**
     * @notes  批量更改状态
     * @param array $params
     * @return bool
     * @author heshihu
     * @date 2022/2/21 18:04
     */
    public static function batchUpdateStatus(array $params)
    {

        Db::startTrans();
        try {
            $book = Skits::where('id', 'in', $params['id'])->where('platform_status', '<>', 1)->findOrEmpty();
            if (!$book->isEmpty() && $params['status'] == 1) {
                self::setError('存在渠道方下线短剧无法上架');
                return false;
            }
            Skits::where('id', 'in', $params['id'])->update([
                'status' => $params['status']
            ]);
            Db::commit();
            return true;
        } catch (\Exception $e) {
            Db::rollback();
            self::setError($e->getMessage());
            return false;
        }
        return true;
    }


    /**
     * @notes 删除
     * @param array $params
     * @return bool
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public static function delete(array $params): bool
    {
        return Skits::destroy($params['id']);
    }


    /**
     * @notes 获取详情
     * @param $params
     * @return array
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public static function detail($params): array
    {
        return Skits::with([
            'actor' => function ($q) {
                $q->withField('id,skits_id,name,photo,role,profile');
            }
        ])->findOrEmpty($params['id'])->toArray();
    }


    /**
     * 获取微信提审详情
     *
     * @param $skitsId
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function getWechatAuditDramaDetail($skitsId)
    {
        $detail = SkitsWechatAudit::where('skits_id', $skitsId)->findOrEmpty();
        if ($detail->isEmpty()) {

            return [];
        }
        $info = WechatService::getDrama($detail->app_id, $detail->drama_id);

        $actorList = json_decode($detail->actor_list ?? '', true);
        foreach ($actorList as &$actor) {
            $actor['photo_url'] = WechatService::getMedia($detail->app_id, $actor['photo_material_id']);
        }

        $detail->media_id_list                 = json_decode($detail->media_id_list, true);
        $detail->actor_list                    = $actorList;
        $auditDetail                           = $info['audit_detail'] ?? [];
        $detail->status                        = $auditDetail['status'] ?? 0;
        $detail->cover_url                     = WechatService::getMedia($detail->app_id, $detail->cover_material_id);
        $detail->authorized_url                = WechatService::getMedia($detail->app_id, $detail->authorized_material_id);
        $detail->qualification_certificate_url = WechatService::getMedia($detail->app_id, $detail->qualification_certificate_material_id);
        $detail->cost_commitment_letter_url    = WechatService::getMedia($detail->app_id, $detail->cost_commitment_letter_material_id);
        $detail->other_material_url            = WechatService::getMedia($detail->app_id, $detail->other_material_material_id);


        return $detail->toArray();
    }


    /**
     * 微信剧目提审
     *
     * @param $params
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function wechatAuditDrama($params)
    {
        $data = self::validateWechatAuditDrama($params);
        if (!$data) {

            return false;
        }

        if (!$audit = self::saveSkitsWechatAudit($data)) {
            self::setError('保存剧目提审信息失败');
            return false;
        }

        $dramaId = WechatService::auditDrama($data);
        if (!$dramaId) {
            self::setError('剧目提审失败');
            return false;
        }
        $audit->drama_id = $dramaId;

        return $audit->save();
    }


    /**
     * 保存微信剧目审核
     *
     * @param $data
     * @return bool
     */
    public static function saveSkitsWechatAudit($data)
    {

        $audit = SkitsWechatAudit::where('app_id', $data['app_id'])->where('skits_id', $data['skits_id'])->findOrEmpty();
        if ($audit->isEmpty()) {
            $audit           = new SkitsWechatAudit();
            $audit->app_id   = $data['app_id'];
            $audit->skits_id = $data['skits_id'];
        }
        $audit->drama_id                              = $data['drama_id'];
        $audit->name                                  = $data['name'];
        $audit->media_count                           = (int)$data['media_count'];
        $audit->media_id_list                         = json_encode($data['media_id_list'], JSON_UNESCAPED_UNICODE);
        $audit->description                           = $data['description'];
        $audit->recommendations                       = $data['recommendations'];
        $audit->cover_material_id                     = $data['cover_material_id'];
        $audit->producer                              = $data['producer'];
        $audit->authorized_material_id                = $data['authorized_material_id'];
        $audit->qualification_type                    = (int)$data['qualification_type'];
        $audit->registration_number                   = $data['registration_number'];
        $audit->qualification_certificate_material_id = $data['qualification_certificate_material_id'];
        $audit->cost_of_production                    = $data['cost_of_production'];
        $audit->cost_commitment_letter_material_id    = $data['cost_commitment_letter_material_id'];
        $audit->expedited                             = $data['expedited'];
        $audit->actor_list                            = json_encode($data['actor_list'], JSON_UNESCAPED_UNICODE);
        $audit->other_material_material_id            = $data['other_material_material_id'];
        $audit->replace_media_list                    = json_encode($data['replace_media_list'], JSON_UNESCAPED_UNICODE);

        if (!$audit->save()) {

            return false;
        }
        return $audit;
    }


    /**
     * 剧集提审验证
     *
     * @param $params
     * @return array|bool
     */
    public static function validateWechatAuditDrama($params)
    {
        $appId                              = $params['app_id'] ?? '';
        $skitsId                            = $params['skits_id'] ?? '';
        $mediaIdList                        = $params['media_id_list'] ?? [];
        $description                        = $params['description'] ?? '';
        $coverMaterialId                    = $params['cover_material_id'] ?? '';
        $authorizedMaterialId               = $params['authorized_material_id'] ?? '';
        $qualificationType                  = $params['qualification_type'] ?? '';
        $registrationNumber                 = $params['registration_number'] ?? '';
        $qualificationCertificateMaterialId = $params['qualification_certificate_material_id'] ?? '';
        $costCommitmentLetterMaterialId     = $params['cost_commitment_letter_material_id'] ?? '';
        $costOfProduction                   = $params['cost_of_production'] ?? '';
        $actorList                          = $params['actor_list'] ?? [];

        if (!$appId) {
            self::setError('请选择要提审的微信小程序');
            return false;
        }
        if (!$skitsId) {
            self::setError('请选择要提审的短剧');
            return false;
        }
        $skits      = Skits::find($skitsId);
        $name       = $skits->skits_name ?? '';
        $producer   = $skits->producer_name ?? '';
        $mediaCount = $skits->episodes_count ?? 0;
        if (!$name) {
            self::setError('请填写短剧剧目名称，首次提审时必填');
            return false;
        }
        if (!$mediaCount) {
            self::setError('请填写剧集数目，首次提审时必填，重新提审时可不填');
            return false;
        }
        if (!$mediaIdList || (count($mediaIdList) != $mediaCount)) {
            self::setError('请选择提审剧集，且提审剧集必须与填写剧集数目保持一致');
            return false;
        }
        if (!$description) {
            self::setError('请填写剧目简介');
            return false;
        }
        if (!$coverMaterialId) {
            self::setError('请上传剧目海报');
            return false;
        }
        if (!$producer) {
            self::setError('请填写短剧剧目制作方');
            return false;
        }
        if (!$authorizedMaterialId) {
            self::setError('请上传《权利声明/播放授权材料》');
            return false;
        }
        if (!$qualificationType) {
            self::setError('请选择剧目资质');
            return false;
        }
        if ($qualificationType == 1) {
            if (!$registrationNumber) {
                self::setError('请填写剧目备案号');
                return false;
            }
            if (!$qualificationCertificateMaterialId) {
                self::setError('请上传《剧目资质证明文件》');
                return false;
            }
        }
        if ($qualificationType == 2) {
            if (!$costCommitmentLetterMaterialId) {
                self::setError('请上传《成本配置比例情况报告》');
                return false;
            }
            if (!$costOfProduction) {
                self::setError('请填写剧目制作成本（单位：万元）');
                return false;
            }
        }

        if (!$actorList || (count($actorList) < 2) || (count($actorList) > 5)) {
            self::setError('请填写演员信息，需填写2-5位演员');
            return false;
        }

        return [
            'app_id'                                => $appId,
            'skits_id'                              => $skitsId,
            'drama_id'                              => $params['drama_id'] ?? '',
            'name'                                  => $name,
            'media_count'                           => $mediaCount,
            'media_id_list'                         => $mediaIdList,
            'description'                           => $description,
            'recommendations'                       => $params['recommendations'] ?? '',
            'cover_material_id'                     => $coverMaterialId,
            'producer'                              => $producer,
            'authorized_material_id'                => $authorizedMaterialId,
            'qualification_type'                    => $qualificationType,
            'registration_number'                   => $registrationNumber,
            'qualification_certificate_material_id' => $qualificationCertificateMaterialId,
            'cost_of_production'                    => $costOfProduction,
            'cost_commitment_letter_material_id'    => $costCommitmentLetterMaterialId,
            'expedited'                             => $params['expedited'] ?? 0,
            'actor_list'                            => $actorList,
            'other_material_material_id'            => $params['other_material_material_id'] ?? '',
            'replace_media_list'                    => $params['replace_media_list'] ?? [],
        ];
    }


    /**
     * 获取微信媒资列表
     *
     * @param $appId
     * @param $skitsId
     * @return array|bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getWechatMediaList($appId, $skitsId, $name = '', $pageNo = 0, $pageSize = 10)
    {
        if (!$appId) {
            self::setError('请选择微信小程序');
            return false;
        }
        $skits = Skits::find($skitsId);

        $offset = ($pageNo - 1) * $pageSize;

        $mediaName = $name ?? ($skits->skits_name ?? '');

        return WechatService::getMediaList([
            'app_id'     => $appId,
            'media_name' => $mediaName,
            'offset'     => $offset,
            'page_size'  => $pageSize,
        ]);
    }


    /**
     * 上传微信临时素材
     *
     * @param $appId
     * @param $file
     * @return array|bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function uploadWechatMedia($appId, $file)
    {
        if (!$mediaId = WechatService::uploadMedia($appId, $file)) {

            return false;
        }

        return ['media_id' => $mediaId];
    }


    /**
     * 上传抖音图片
     *
     * @param $appId
     * @param $picUrl
     * @return array|bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function uploadDouyinPic($appId, $picUrl)
    {
        $app = App::find($appId);
        if (!$picId = DouyinService::uploadPic($app->app_id, $picUrl)) {

            return false;
        }

        return ['pic_id' => $picId];
    }


    /**
     * 创建抖音短剧
     *
     * @param $params
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function createDouyinVideo($params)
    {
        $appId   = $params['app_id'] ?? 0;
        $skitsId = $params['skits_id'] ?? 0;
        $app     = App::find($appId);

        $skits       = Skits::find($skitsId);
        $categoryIds = explode(',', $skits->category_id);
        $picId       = DouyinService::uploadPic($app->app_id, $skits->thumb);
        if (!$picId) {
            self::setError('上传抖音短剧封面图失败');
            return false;
        }
        $data   = [
            'title'             => $skits->skits_name ?? '',
            'seq_num'           => $skits->episodes_count ?? 0,
            'cover_list'        => [$picId],
            'year'              => $skits->year,
            'album_status'      => $skits->is_finish ? 2 : 3,
            'recommendation'    => $skits->recommendation ?? '',
            'desp'              => $skits->intro ?? '',
            'tag_list'          => self::getDouyinTags($categoryIds),
            'qualification'     => 1,
            'record_audit_info' => [
                'record_material' => [
                    'name'                    => $skits->skits_name ?? '',
                    'duration'                => $skits->duration ?? 0,
                    'seqs_count'              => $skits->episodes_count ?? 0,
                    'production_organisation' => $skits->producer_name ?? '',
                    'director'                => getArrayByString($skits->director ?? ''),
                    'producer'                => getArrayByString($skits->producer_name ?? ''),
                    'actor'                   => $skits->actor->column('name'),
                    'summary'                 => $skits->intro ?? '',
                    'cost_distribution_uri'   => $params['cost_distribution_uri'] ?? '',
                    'playlet_production_cost' => self::getDouyinCost($skits->playlet_production_cost)
                ]
            ]
        ];
        $result = DouyinService::createVideo($app->app_id, $data);
        if ($result['err_code'] != 0) {
            self::setError($result['msg'] ?? '创建抖音短剧失败');
            return false;
        }

        $skits->douyin_app_id   = $app->app_id;
        $skits->douyin_drama_id = $result['album_id'] ?? '';
        $skits->douyin_status   = 1;

        return $skits->save();
    }


    /**
     * 编辑抖音短剧/添加剧集
     *
     * @param $params
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function editDouyinVideo($params)
    {
        $appId       = $params['app_id'] ?? 0;
        $skitsId     = $params['skits_id'] ?? 0;
        $type        = $params['type'] ?? 2;
        $episodesIds = $params['episodes_ids'] ?? [];
        $app         = App::find($appId);
        $skits       = Skits::find($skitsId);
        $picId       = DouyinService::uploadPic($app->app_id, $skits->thumb);
        if (!$picId) {
            self::setError('上传抖音短剧封面图失败');
            return false;
        }
        $episodeList     = SkitsEpisodes::field('id,episodes_name,episodes_order,douyin_media_id,dy_status')
            ->whereIn('id', $episodesIds)
            ->order('episodes_order', 'asc')
            ->select();
        $episodeInfoList = [];
        foreach ($episodeList as $item) {
            if ($item->douyin_media_id) {
                $episodeInfoList[] = [
                    'title'         => $item->episodes_name ?? '',
                    'seq'           => $item->episodes_order ?? 0,
                    'cover_list'    => [$picId],
                    'open_video_id' => $item->douyin_media_id
                ];
            }
        }

        // 添加剧集
        if ($type == 2) {
            if (!empty($episodeInfoList)) {
                $result = DouyinService::editVideo($app->app_id, $skits->douyin_drama_id, [], $episodeInfoList);
                if ($result['err_code'] != 0) {
                    self::setError($result['msg'] ?? '添加抖音剧集失败');
                    return false;
                }

                foreach ($episodeList as $item) {
                    $item->dy_status = 2;
                    $item->save();
                }
            }

            return true;
        } else { // TODO 编辑短剧
            $categoryIds = explode(',', $skits->category_id);
            $data        = [
                'title'             => $skits->skits_name ?? '',
                'seq_num'           => $skits->episodes_count ?? 0,
                'cover_list'        => [$picId],
                'year'              => $skits->year,
                'album_status'      => $skits->is_finish ? 2 : 3,
                'recommendation'    => $skits->recommendation ?? '',
                'desp'              => $skits->intro ?? '',
                'tag_list'          => self::getDouyinTags($categoryIds),
                'qualification'     => 1,
                'record_audit_info' => [
                    'record_material' => [
                        'name'                    => $skits->skits_name ?? '',
                        'duration'                => $skits->duration ?? 0,
                        'seqs_count'              => $skits->episodes_count ?? 0,
                        'production_organisation' => $skits->producer_name ?? '',
                        'director'                => getArrayByString($skits->director ?? ''),
                        'producer'                => getArrayByString($skits->producer_name ?? ''),
                        'actor'                   => $skits->actor->column('name'),
                        'summary'                 => $skits->intro ?? '',
                        'cost_distribution_uri'   => $params['cost_distribution_uri'] ?? '',
                        'playlet_production_cost' => self::getDouyinCost($skits->playlet_production_cost)
                    ]
                ]
            ];

            $result = DouyinService::editVideo($app->app_id, $skits->douyin_drama_id, $data, $episodeInfoList);
            if ($result['err_code'] != 0) {
                self::setError($result['msg'] ?? '编辑抖音短剧失败');
                return false;
            }

            return true;
        }
    }


    /**
     * 抖音送审
     *
     * @param $params
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function douyinVideoReview($params)
    {
        $skitsId = $params['skits_id'] ?? 0;
        $appId   = $params['app_id'] ?? 0;
        if (!$skitsId || !$appId) {

            return false;
        }
        $skits  = Skits::find($skitsId);
        $app    = App::find($appId);
        $result = DouyinService::reviewVideo($app->app_id, $skits->douyin_drama_id ?? '');
        if ($result['err_code'] != 0) {
            self::setError($result['msg'] ?? '抖音送审失败');
            return false;
        }
        $skits->douyin_status = 2;

        return $skits->save();
    }


    /**
     * 抖音短剧授权
     *
     * @param $params
     * @return bool
     * @throws \GuzzleHttp\Exception\GuzzleException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function authDouyinVideo($params)
    {
        $skitsId    = $params['skits_id'] ?? 0;
        $appId      = $params['app_id'] ?? 0;
        $authAppIds = $params['auth_app_ids'] ?? [];
        if (!$skitsId || !$appId || !$authAppIds) {

            return false;
        }
        !is_array($authAppIds) && $authAppIds = [$authAppIds];
        $skits     = Skits::find($skitsId);
        $app       = App::find($appId);
        $appIdList = [];
        foreach ($authAppIds as $item) {
            $authApp = App::find($item);
            if ($authApp->channel == $app->channel) {
                $appIdList[] = $authApp->app_id ?? '';
            }
        }

        if ($appIdList) {

            return DouyinService::authAlbum($app->app_id, $skits->douyin_drama_id ?? '', $appIdList);
        }

        return false;
    }


    /**
     * 获取抖音成本配置
     *
     * @param $cost
     * @return int
     */
    public static function getDouyinCost($cost)
    {
        if ($cost <= 30) {

            return 10;
        }
        if ($cost > 30 && $cost <= 100) {

            return 20;
        }

        return 30;
    }


    /**
     * 获取抖音标签
     *
     * @param $categoryIds
     * @return array
     */
    public static function getDouyinTags($categoryIds)
    {
        $category = SkitsCategory::whereIn('id', $categoryIds)->column('name') ?? [];
        $tags     = [];
        foreach ($category as $item) {
            if (($key = array_search($item, config('tag'))) !== false) {
                $tags[] = $key;
            }
        }

        return empty($tags) ? [46] : $tags;
    }
}
